#ifndef ELSLIDER_H
#define ELSLIDER_H

#include "elcomponent.h"

class QPropertyAnimation;
class QEnterEvent;

// BUG: Slider's tooltip and value(property) need to be fixed
// TODO: need to rewrite
class ElSlider : public ElComponent
{
    Q_OBJECT
public:
    ElSlider(QWidget *parent = nullptr);

    int min() const;
    void setMin(int min);

    int max() const;
    void setMax(int max);

    int value() const;
    void setValue(int value);

    void setTooltip(ElTooltip *tooltip);
    ElTooltip *tooltip() const;

signals:
    void sliderPressed();
    void sliderReleased();
    void sliderMoved();
    void valueChanged(int value);

protected:
    int _min{};
    int _max{100};
    int _value{};

    bool event(QEvent *e) override;
    void paintEvent(QPaintEvent *e) override;
    void mousePressEvent(QMouseEvent *e) override;
    void initPalette() override;

    class ElSliderCircle : public ElComponent
    {
    public:
        ElSliderCircle(ElSlider *parent);

        void updateTooltip(int value); // new value would be shown in tooltip

        qreal radius() const;
        void setRadius(qreal radius);

        bool isStepStop() const;
        void setStepStop(bool stepStop);

        static const qreal Init_Radius;

    protected:
        bool event(QEvent *e) override;
        void paintEvent(QPaintEvent *e) override;
        void enterEvent(QEvent *e) override;
        void leaveEvent(QEvent *e) override;
        void mousePressEvent(QMouseEvent *e) override;
        void mouseReleaseEvent(QMouseEvent *e) override;
        void mouseMoveEvent(QMouseEvent *e) override;
        void initPalette() override;

    private:
        qreal _radius{Init_Radius};
        bool _stepStop = false;
        QPropertyAnimation *_animation = nullptr;
        ElSlider *_slider = nullptr;
    } *sliderCircle = nullptr;

private:
    Q_PROPERTY(int min READ min WRITE setMin)
    Q_PROPERTY(int max READ max WRITE setMax)
    Q_PROPERTY(int value READ value WRITE setValue)

    static qreal Slider_Height;
};

#endif // ELSLIDER_H
